True if value is currently a member of target, false otherwise. Exactly the same as set_has - this is the name that matches list_contains, stack_contains and queue_contains.
set_contains(target, value) -> bool| Name | Type |
|---|---|
target | set |
value | element |
bool
true if value is currently a member of target, a set, false otherwise. Checking is fast no matter how many values target already holds.
This is exactly the same as set_has - the same question, the same answer, the same speed. It has a second name so that the question is spelled the same way on every container: list_contains for a list, stack_contains for a stack, queue_contains for a queue and set_contains for a set. Use whichever you like; a game that already says set_has keeps working.
| You do this | What happens |
|---|---|
| ask about a value that was never added | false |
| ask about a value that was added and then removed | false |
| ask an empty set | false |
| give it a list | refused when checked. A list has its own, list_contains |
/// @type {set<int>}
var visited = [5];
var has5 = set_contains(visited, 5); // true
var has6 = set_contains(visited, 6); // falseJust the hash set's contains() - O(1) average, the identical code set_has writes.